app.controller('goodsBrandController',function ($scope,$controller,goodsBrandService){
    $controller("commonController",{$scope:$scope});
    //全部品牌列表
    $scope.findAll = function () {
        goodsBrandService.findAll().success(function (response) {
            $scope.list = response;

        });

    }

//分页
    $scope.findPageList = function (pageNum, pageSize) {
        goodsBrandService.findPageList(pageNum, pageSize).success(
            function (response) {
                $scope.list = response.result;
                //更新总记录数
                $scope.paginationConf.totalItems = response.total;
            }
        );
    }

//查询单个品牌
    $scope.findOne = function (id) {
        goodsBrandService.findOne(id).success(
            function (response) {
                $scope.entity = response;
            }
        );
    }


//保存
    $scope.save = function () {
        var object = null;
        if ($scope.entity.id != null) {
            object = goodsBrandService.updateBrand($scope.entity)
        } else {
            object = goodsBrandService.addBrand($scope.entity)
        }
        object.success(
            function (response) {
                if (200 == response.code) {
                    $scope.reloadList();//刷新
                    $scope.selectedBrandId = [];
                } else {
                    alert(response.message);
                }
            }
        );
    }
//删除品牌
    $scope.deleteBrand = function () {
        goodsBrandService.deleteBrand($scope.selected).success(
            function (response) {
                if (200 == response.code) {
                    $scope.reloadList();
                }
            }
        );

    }

//模块查询
    $scope.dpbrand = {};
    $scope.search = function (pageNum, pageSize) {
        goodsBrandService.search(pageNum, pageSize, $scope.dpbrand).success(
            function (response) {
                $scope.list = response.result;
                //刷新纪录总数
                $scope.paginationConf.totalItems = response.total;
            }
        );
    }
});